package io.gitee.loulan_yxq.owner.poi.excel.test;

import io.gitee.loulan_yxq.owner.core.io.ResourceTool;
import io.gitee.loulan_yxq.owner.core.tool.CharsetTool;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;

/*********************************************************
 ** excel水印标注
 ** <br><br>
 ** Date: Created in 2022/7/26 11:13
 ** @author loulan
 ** @version 0.0.0
 *********************************************************/
public class ExcelSign {

    /**
     * excel里面插入隐藏的图片
     * @param       
     * @return
     * @exception  
     * @author     :loulan
     * */
    @Test
    public void sign() throws IOException {
        XSSFWorkbook workbook = new XSSFWorkbook();

        //int pictureIdx = workbook.addPicture(ResourceTool.getInputStream("/img/123.jpg"), Workbook.PICTURE_TYPE_JPEG);
        String a = "xxxxx";
        int pictureIdx = workbook.addPicture(a.getBytes(), Workbook.PICTURE_TYPE_JPEG);
        XSSFSheet sheet = workbook.createSheet();
        XSSFRow row = sheet.createRow(0);
        XSSFCell cell = row.createCell(0);

        cell.setCellValue("123");

        XSSFClientAnchor anchor = workbook.getCreationHelper().createClientAnchor();
        Drawing drawing = sheet.createDrawingPatriarch();
        anchor.setCol1(0);
        anchor.setRow1(0);
        Picture pict = drawing.createPicture(anchor, pictureIdx);
        pict.resize(0);

        workbook.write(new FileOutputStream("target/xxxx.xlsx"));
    }

    @Test
    public void test() throws IOException {
        String s = ResourceTool.readStr("/img/image1.emf", CharsetTool.CHARSET_UTF_8);
        System.out.println(s);
    }
}
